/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.pay.view;

import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;
import com.qihoo.gamecenter.sdk.common.d.a.a;
import com.qihoo.gamecenter.sdk.common.i.q;
import com.qihoo.gamecenter.sdk.common.i.s;
import com.qihoo.gamecenter.sdk.pay.j.d.a;
import com.qihoo.gamecenter.sdk.pay.k.c;
import java.lang.reflect.Method;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class PayRecordView extends LinearLayout implements AbsListView.OnScrollListener {
    private long a = 0L;
    private boolean b = false;
    private boolean c = false;
    private String d = "succ";
    private TextView e;
    private TextView f;
    private ListView g;
    private com.qihoo.gamecenter.sdk.pay.a.a h;
    private ArrayList i;
    private TextView j;
    private TextView k;
    private TextView l;
    private TextView m;
    private Intent n;
    private Context o;
    private com.qihoo.gamecenter.sdk.pay.res.b p;
    private boolean q;
    private com.qihoo.gamecenter.sdk.pay.j.d r;
    private View.OnClickListener s = new View.OnClickListener() {
        public void onClick(View paramView) {
            String str = String.valueOf(paramView.getTag());
            if (PayRecordView.a(PayRecordView.this).equals(str))
                return;
            if (PayRecordView.b(PayRecordView.this))
                PayRecordView.c(PayRecordView.this);
            if (paramView == PayRecordView.d(PayRecordView.this)) {
                PayRecordView.a(PayRecordView.this, PayRecordView.d(PayRecordView.this), true);
                PayRecordView.a(PayRecordView.this, PayRecordView.e(PayRecordView.this), false);
                PayRecordView.a(PayRecordView.this, PayRecordView.f(PayRecordView.this), false);
            }
            else if (paramView == PayRecordView.e(PayRecordView.this)) {
                PayRecordView.a(PayRecordView.this, PayRecordView.d(PayRecordView.this), false);
                PayRecordView.a(PayRecordView.this, PayRecordView.e(PayRecordView.this), true);
                PayRecordView.a(PayRecordView.this, PayRecordView.f(PayRecordView.this), false);
            }
            else if (paramView == PayRecordView.f(PayRecordView.this)) {
                PayRecordView.a(PayRecordView.this, PayRecordView.d(PayRecordView.this), false);
                PayRecordView.a(PayRecordView.this, PayRecordView.e(PayRecordView.this), false);
                PayRecordView.a(PayRecordView.this, PayRecordView.f(PayRecordView.this), true);
            }
            PayRecordView.a(PayRecordView.this, str);
            PayRecordView.this.a();
        }
    };
    private a t = new a(null);

    public PayRecordView(Context paramContext) {
        super(paramContext);
    }

    public PayRecordView(Context paramContext, Intent paramIntent, Handler paramHandler) {
        super(paramContext);
        this.o = paramContext;
        this.n = paramIntent;
        this.p = com.qihoo.gamecenter.sdk.pay.res.b.a(paramContext);
        this.q = paramIntent.getBooleanExtra("screen_orientation", true);
        this.i = new ArrayList();
        setOrientation(1);
        setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        b();
        c();
    }

    private void b() {
        LinearLayout.LayoutParams localLayoutParams1 = new LinearLayout.LayoutParams(-1, s.b(this.o, 36.0F));
        localLayoutParams1.bottomMargin = s.b(this.o, 10.0F);
        localLayoutParams1.gravity = 1;
        LinearLayout localLinearLayout = new LinearLayout(this.o);
        localLinearLayout.setId(com.qihoo.gamecenter.sdk.pay.b.t.ordinal());
        localLinearLayout.setLayoutParams(localLayoutParams1);
        localLinearLayout.setGravity(17);
        localLinearLayout.setOrientation(0);
        this.p.a(localLinearLayout, -1073741717);
        addView(localLinearLayout);
        LinearLayout.LayoutParams localLayoutParams2;
        if (this.q)
            localLayoutParams2 = new LinearLayout.LayoutParams(s.b(this.o, 68.0F), s.b(this.o, 24.0F));
        else
            localLayoutParams2 = new LinearLayout.LayoutParams(s.b(this.o, 76.0F), s.b(this.o, 24.0F));
        localLayoutParams2.leftMargin = s.b(this.o, 10.0F);
        localLayoutParams2.rightMargin = s.b(this.o, 10.0F);
        this.j = new TextView(this.o);
        this.j.setLayoutParams(localLayoutParams2);
        this.j.setTextColor(-11909573);
        this.j.setTextSize(1, s.a(this.o, 13.3F));
        this.j.setText(com.qihoo.gamecenter.sdk.common.d.a.a(a.a.bq));
        this.j.setGravity(17);
        this.j.setBackgroundColor(0);
        this.j.setOnClickListener(this.s);
        this.j.setTag("all");
        localLinearLayout.addView(this.j);
        this.k = new TextView(this.o);
        this.k.setLayoutParams(localLayoutParams2);
        this.k.setTextColor(-1);
        this.k.setTextSize(1, s.a(this.o, 13.3F));
        this.k.setText(com.qihoo.gamecenter.sdk.common.d.a.a(a.a.bo));
        this.k.setGravity(17);
        this.k.setBackgroundDrawable(this.p.a(-1073741747));
        this.k.setOnClickListener(this.s);
        this.k.setTag("succ");
        localLinearLayout.addView(this.k);
        this.l = new TextView(this.o);
        this.l.setLayoutParams(localLayoutParams2);
        this.l.setTextColor(-11909573);
        this.l.setTextSize(1, s.a(this.o, 13.3F));
        this.l.setText(com.qihoo.gamecenter.sdk.common.d.a.a(a.a.bp));
        this.l.setGravity(17);
        this.l.setBackgroundColor(0);
        this.l.setOnClickListener(this.s);
        this.l.setTag("fail");
        localLinearLayout.addView(this.l);
    }

    private void c() {
        LinearLayout localLinearLayout = new LinearLayout(this.o);
        localLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(-1, 0, 1.0F));
        localLinearLayout.setOrientation(0);
        localLinearLayout.setGravity(1);
        if (this.q)
            localLinearLayout.setPadding(s.b(this.o, 60.0F), 0, s.b(this.o, 60.0F), 0);
        addView(localLinearLayout);
        localLinearLayout.addView(d());
        localLinearLayout.addView(e());
        localLinearLayout.addView(f());
    }

    private View d() {
        LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-1, -1);
        localLayoutParams.leftMargin = s.b(this.o, 10.0F);
        localLayoutParams.rightMargin = s.b(this.o, 10.0F);
        localLayoutParams.bottomMargin = s.b(this.o, 10.0F);
        this.g = new ListView(this.o);
        this.g.setLayoutParams(localLayoutParams);
        this.g.setScrollingCacheEnabled(false);
        this.g.setFadingEdgeLength(2);
        this.g.setCacheColorHint(0);
        this.g.setBackgroundColor(0);
        this.g.setDividerHeight(0);
        this.g.setVisibility(8);
        this.p.a(this.g, -1073741729);
        this.g.setOnScrollListener(this);
        this.g.setOnItemClickListener(this.t);
        LinearLayout localLinearLayout = new LinearLayout(this.o);
        this.e = new TextView(this.o);
        this.e.setLayoutParams(new LinearLayout.LayoutParams(-1, s.b(this.o, 35.0F)));
        this.e.setGravity(17);
        this.e.setText(com.qihoo.gamecenter.sdk.common.d.a.a(a.a.l));
        this.e.setTextSize(1, 14.0F);
        this.e.setTextColor(-11842745);
        localLinearLayout.addView(this.e);
        this.g.addFooterView(localLinearLayout);
        this.h = new com.qihoo.gamecenter.sdk.pay.a.a(this.o, this.n);
        this.g.setAdapter(this.h);
        return this.g;
    }

    private View e() {
        LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-2, -2);
        localLayoutParams.gravity = 17;
        this.f = new TextView(this.o);
        this.f.setLayoutParams(localLayoutParams);
        this.f.setCompoundDrawablePadding(s.b(this.o, 15.0F));
        this.p.a(this.f, 0, 1073741916, 0, 0);
        this.f.setText(com.qihoo.gamecenter.sdk.common.d.a.a(a.a.ay));
        this.f.setTextSize(1, 24.0F);
        this.f.setTextColor(-3429035);
        this.f.setGravity(17);
        this.f.setVisibility(8);
        return this.f;
    }

    private View f() {
        LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-1, s.b(this.o, 35.0F));
        localLayoutParams.gravity = 17;
        this.m = new TextView(this.o);
        this.m.setLayoutParams(localLayoutParams);
        this.m.setGravity(17);
        this.m.setText(com.qihoo.gamecenter.sdk.common.d.a.a(a.a.l));
        this.m.setTextSize(1, s.a(this.o, 14.0F));
        this.m.setTextColor(-11842745);
        return this.m;
    }

    private void a(TextView paramTextView, boolean paramBoolean) {
        if (paramBoolean) {
            paramTextView.setBackgroundDrawable(this.p.a(-1073741747));
            paramTextView.setTextColor(-1);
        }
        else {
            paramTextView.setBackgroundColor(0);
            paramTextView.setTextColor(-11909573);
        }
    }

    public void a(int paramInt) {
        if (this.b)
            return;
        if (paramInt == 0) {
            a(true);
            this.i.clear();
            this.h.a(this.i);
            this.c = false;
        }
        else {
            a(false);
        }
        this.a = s.g(this.o);
        this.n.putExtra("Type", this.d);
        if (this.r != null) {
            this.r.cancel(true);
            this.r = null;
            c.a("PayRecordView", new Object[] { "Last load task is interrupted..." });
        }
        this.r = new com.qihoo.gamecenter.sdk.pay.j.d(this.o, paramInt, this.n);
        this.r.a(new d.a() {
            public void a(String paramString) {
                PayRecordView.a(PayRecordView.this, null);
            }
        });
        this.r.a(new b(null), new String[0]);
    }

    public void a() {
        a(0);
    }

    private void g() {
        this.b = false;
        this.e.setVisibility(8);
        this.m.setVisibility(8);
    }

    private void a(boolean paramBoolean) {
        this.b = true;
        if (paramBoolean) {
            this.m.setVisibility(0);
            this.g.setVisibility(8);
            this.f.setVisibility(8);
        }
        else {
            this.e.setVisibility(0);
            this.g.setSelection(this.g.getCount());
        }
    }

    public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt) {
        if ((0 != paramInt) || (this.c)
                || (paramAbsListView.getLastVisiblePosition() != paramAbsListView.getCount() - 1))
            return;
        a(this.h.getCount());
    }

    public void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3) {}

    public void a(View paramView, int paramInt) {
        if (paramView.getBottom() + paramView.getHeight() <= this.g.getBottom())
            return;
        if (Build.VERSION.SDK_INT >= 8)
            a(paramView.getBottom() + paramView.getHeight() - this.g.getBottom(), 500);
        else
            this.g.setSelection(paramInt);
    }

    public void a(int paramInt1, int paramInt2) {
        try {
            Class localClass = this.g.getClass();
            Method localMethod = localClass.getMethod("smoothScrollBy", new Class[] { Integer.TYPE, Integer.TYPE });
            localMethod.invoke(this.g, new Object[] { Integer.valueOf(paramInt1), Integer.valueOf(paramInt2) });
        } catch (SecurityException localSecurityException) {
            c.c("PayRecordView", new Object[] { localSecurityException.toString() });
        } catch (NoSuchMethodException localNoSuchMethodException) {
            c.c("PayRecordView", new Object[] { localNoSuchMethodException.toString() });
        } catch (Exception localException) {
            c.c("PayRecordView", new Object[] { localException.toString() });
        }
    }

    private class a implements AdapterView.OnItemClickListener {
        public void onItemClick(AdapterView paramAdapterView, View paramView, int paramInt, long paramLong) {
            c.a("PayRecordView", new Object[] { " view=", paramView, " position=", Integer.valueOf(paramInt), " id=",
                    Long.valueOf(paramLong) });
            PayRecordView.l(PayRecordView.this).b(paramInt);
            View localView = PayRecordView.l(PayRecordView.this).a();
            c.a("PayRecordView", new Object[] { " lastClickedView=", localView });
            if (localView != null) {
                if (paramView == localView) {
                    if (PayRecordView.l(PayRecordView.this).b(localView)) {
                        PayRecordView.l(PayRecordView.this).a(localView);
                        PayRecordView.l(PayRecordView.this).b(-1);
                    }
                    else {
                        PayRecordView.l(PayRecordView.this).a(localView, paramInt);
                        PayRecordView.this.a(paramView, paramInt);
                    }
                    return;
                }
                PayRecordView.l(PayRecordView.this).a(localView);
            }
            PayRecordView.l(PayRecordView.this).a(paramView, paramInt);
            PayRecordView.this.a(paramView, paramInt);
        }
    }

    private class b extends com.qihoo.gamecenter.sdk.common.h.b {
        public void a(String paramString, Context paramContext) {
            super.a(paramString, paramContext);
            c.a("PayRecordView", new Object[] { " Enter callback: result =", paramString });
            JSONObject localJSONObject1 = b();
            if (localJSONObject1 == null) {
                if (PayRecordView.g(PayRecordView.this).isEmpty()) {
                    PayRecordView.h(PayRecordView.this).setVisibility(0);
                    PayRecordView.i(PayRecordView.this).setVisibility(8);
                }
                return;
            }
            int i = localJSONObject1.optInt("error_code");
            c.a("PayRecordView", new Object[] { "The pay records request, errorCode=", Integer.valueOf(i) });
            if (i != 0) {
                if ((i == 4010201) || (i == 4010202)) {
                    Intent localIntent = new Intent();
                    localIntent.putExtra("action_code", i);
                    localIntent.setFlags(536870912);
                    localIntent.setClassName(PayRecordView.j(PayRecordView.this),
                            "com.qihoo.gamecenter.sdk.activity.ContainerActivity");
                    PayRecordView.j(PayRecordView.this).startActivity(localIntent);
                    return;
                }
                if (PayRecordView.g(PayRecordView.this).isEmpty()) {
                    PayRecordView.h(PayRecordView.this).setVisibility(0);
                    PayRecordView.i(PayRecordView.this).setVisibility(8);
                }
                q.a(PayRecordView.j(PayRecordView.this), com.qihoo.gamecenter.sdk.common.d.a.a(a.a.m), 0, 80);
                return;
            }
            int j = localJSONObject1.optInt("total");
            c.a("PayRecordView", new Object[] { "The pay records total =", Integer.valueOf(j) });
            if (j <= 0) {
                PayRecordView.h(PayRecordView.this).setVisibility(0);
                PayRecordView.i(PayRecordView.this).setVisibility(8);
                PayRecordView.a(PayRecordView.this, true);
                return;
            }
            JSONObject localJSONObject2 = null;
            JSONArray localJSONArray = localJSONObject1.optJSONArray("records");
            int k = (localJSONArray == null) ? 0 : localJSONArray.length();
            for (int l = 0; l < k; ++l)
                try {
                    localJSONObject2 = localJSONArray.getJSONObject(l);
                    if (localJSONObject2 != null) {
                        com.qihoo.gamecenter.sdk.pay.d locald = new com.qihoo.gamecenter.sdk.pay.d();
                        locald.a(localJSONObject2.getString("id"));
                        locald.a(Integer.parseInt(s.c(localJSONObject2.getString("status"))));
                        locald.a(Long.parseLong(s.c(localJSONObject2.getString("created_time"))));
                        locald.b(Integer.parseInt(s.c(localJSONObject2.getString("success_time"))));
                        locald.c(Integer.parseInt(s.c(localJSONObject2.getString("amount"))));
                        locald.b(localJSONObject2.getString("pay_type"));
                        locald.c(localJSONObject2.getString("pay_type_name"));
                        locald.d(localJSONObject2.getString("product_name"));
                        locald.e(localJSONObject2.getString("status_text"));
                        PayRecordView.g(PayRecordView.this).add(locald);
                    }
                } catch (JSONException localJSONException) {
                    c.c("PayRecordView", new Object[] { localJSONException.toString() });
                }
            if (PayRecordView.g(PayRecordView.this).isEmpty()) {
                PayRecordView.h(PayRecordView.this).setVisibility(0);
                PayRecordView.i(PayRecordView.this).setVisibility(8);
                return;
            }
            if (PayRecordView.g(PayRecordView.this).size() >= j)
                PayRecordView.a(PayRecordView.this, true);
            PayRecordView.l(PayRecordView.this).a(PayRecordView.k(PayRecordView.this));
            PayRecordView.l(PayRecordView.this).a(PayRecordView.g(PayRecordView.this));
            PayRecordView.h(PayRecordView.this).setVisibility(8);
            PayRecordView.i(PayRecordView.this).setVisibility(0);
            long l1 = ((com.qihoo.gamecenter.sdk.pay.d) PayRecordView.g(PayRecordView.this).get(0)).c();
            if (l1 > s.a) {
                s.a = l1;
                s.f(PayRecordView.j(PayRecordView.this));
            }
            c.a("PayRecordView", new Object[] { " time=", Long.valueOf(l1), " curbigtime=", Long.valueOf(s.a),
                    " lastbigtime=", Long.valueOf(PayRecordView.k(PayRecordView.this)) });
        }

        public void a() {
            PayRecordView.c(PayRecordView.this);
        }
    }
}